<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery-3.3.1.min.js"></script>
    <style>
        .box {
            width: 250px;
            height: 52px;
            padding: 15px 30px;
            border: 2px solid #ccc;
            border-radius: 16px;
            margin: 0 auto;
        }
        
        .box .count {
            width: 60px;
            color: #666;
            font-size: 280%;
            line-height: 50px;
            padding-left: 6px;
            margin-left: 5px;
            border: 1px solid #fff
        }
        
        .box div {
            margin-left: 5px;
            float: left;
            width: 50px;
            height: 50px;
            border-radius: 50px;
            border: 1px solid #666;
        }
        
        .gray {
            background-color: #eee;
        }
        
        .red {
            background-color: red;
        }
        
        .yellow {
            background-color: yellow;
        }
        
        .green {
            background-color: #26ff00;
        }
    </style>
</head>

<body>
    <div class="box">
        <div id="red" class="red"></div>
        <div id="yellow"></div>
        <div id="green"></div>
        <div class="count" id="count">30</div>
    </div>
    <script>
        var id = setInterval(chaneg, 1000);
        var flag = red;

        function chaneg() {
            $("#count").html(parseInt($("#count").html()) - 1);
            if ($("#count").html() == 0) {
                if (flag == red) {
                    flag = green;
                    $("#red").removeClass("red");
                    $("#green").addClass("green");
                    $("#count").html(35);
                } else if (flag == green) {
                    $("#green").removeClass("green");
                    $("#yellow").addClass("yellow");
                    flag = yellow;
                    $("#count").html(5);
                } else {
                    $("#yellow").removeClass("yellow");
                    $("#red").addClass("red");
                    flag = red;
                    $("#count").html(30);
                }
            }
        }
    </script>
</body>

</html>